package com.jia.controller;

import com.jia.dto.admin.UserDto;
import com.jia.entity.User;
import com.jia.service.UserService;
import com.jia.vo.Result;
import com.jia.vo.ResultCodeEnum;
import com.jia.vo.admin.DepositUserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
@Schema(description = "用户管理表")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户管理列表
     * @param page
     * @param limit
     * @param userDto
     * @return
     */
    @GetMapping("/userList/{page}/{limit}")
    @Operation(description = "用户列表")
    public Result<Map<String,Object>> getUserList(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit,
            UserDto userDto
    ){
        Map<String,Object> map=new HashMap<>();
        map.put("userManager",userService.userList(page,limit,userDto));
        map.put("depositUser",userService.depositUser(page,limit,userDto));
       return Result.build(map, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改状态
     * @param id
     * @return
     */
    @GetMapping("/updateState/{id}")
    @Operation(summary = "修改用户状态")
    public Result updateState(@PathVariable("id") int id) {
        userService.updateState(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 押金记录删除
     * @param id
     * @return
     */
    @GetMapping("/deleteUserDeposit/{id}")
    @Operation(summary = "删除用户押金记录")
    public Result deleteUserDeposit(@PathVariable("id") int id) {
        userService.deleteUserDeposit(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 退还押金
     * @param id
     * @return
     */
    @GetMapping("/getReturnDeposit/{id}")
    @Operation(summary = "退还押金")
    public Result getReturnDeposit(@PathVariable("id") int id) {
        userService.getReturnDeposit(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/deposit_info/{item}/{charItem}")
    @Operation(summary = "首页每日信息")
    public Result<DepositUserInfo> deposit_info(@PathVariable("item") String item,@PathVariable("charItem") String charItem) {
        Map<String,Object> map=new HashMap<>();
        //每日押金详细信息
       map.put("depositInfo",userService.depositUserInfo(charItem));
        //每月套餐的信息
        map.put("comboInfo",userService.comboInfo(item));
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/depositUser")
    @Operation(summary = "退款押金用户")
    public Result<List<User>> depositUser() {
        List<User> users = userService.depositList();
        return Result.build(users, ResultCodeEnum.SUCCESS);
    }


}
